package com.manor.im.fragment

import android.os.Bundle
import android.text.TextUtils
import androidx.recyclerview.widget.LinearLayoutManager
import com.manor.common.dialog.XToast
import com.manor.common.fragment.BaseFragment
import com.manor.im.R
import com.manor.im.dialog.GroupSearchDialog
import com.tencent.imsdk.v2.V2TIMCallback
import com.tencent.imsdk.v2.V2TIMManager
import com.tencent.qcloud.tim.uikit.utils.ToastUtil
import kotlinx.android.synthetic.main.fragment_group_recommend.*

/**
 * @date  2020/7/24  9:21
 * @version 1.0
 */
class GroupRecommendFragment :BaseFragment(){


    companion object{
        fun newInstance(): GroupRecommendFragment {
            val args = Bundle()
            val fragment = GroupRecommendFragment()
            fragment.arguments = args
            return fragment
        }
    }


    override fun getLayoutRes(): Int = R.layout.fragment_group_recommend


    override fun initView() {
        mRecycler.layoutManager = LinearLayoutManager(context,LinearLayoutManager.VERTICAL,false)

        tvSearch.setOnClickListener {
            context?.let { it1 -> GroupSearchDialog.load(it1) }
//            XPopup.Builder(context)
//                    .asInputConfirm("请输入完整群号","", OnInputConfirmListener{
//                        content ->
//                        addGroup(content.trim())
//                    }).show()

        }

        R.layout.item_group_recommend
    }


    fun addGroup(id: String) {
        val content: String = ""
        if (TextUtils.isEmpty(id)) {
            return
        }
        V2TIMManager.getInstance().joinGroup(id, content, object : V2TIMCallback {
            override fun onError(code: Int, desc: String) {
                ToastUtil.toastShortMessage("Error code = $code, desc = $desc")
            }

            override fun onSuccess() {
                context?.let { XToast.load(it,"\uD83D\uDE03申请成功，已通知管理员尽快处理")  }
            }
        })
    }


}